#encoding:utf-8
from django.utils.dateparse import parse_datetime,parse_date
from django.utils import timezone
import pytz
from django.conf import settings
import datetime

# 转化字符串为包含时区信息的datetime对象
# 输入：代表时间的字符串,必须包含日期与时间,格式为 2012-08-07 11:00:00
# 输出: datetime 
#       datetime.datetime(2012, 8, 7, 11, 0, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>)

timeFormat='%Y-%m-%d %H:%M:%S'

def getDatetime(time):
    naive = parse_datetime(time)
    if(timezone.is_aware(naive)):
        naive = naive.replace(tzinfo=None)
    aware = pytz.timezone(settings.TIME_ZONE).localize(naive, is_dst=None)
    return aware


# 获得包含时区信息的当前时间，类型为datetime
#    datetime.datetime(2012, 8, 7, 11, 30, 20, 864000, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>)

def getNow():
    return timezone.localtime(timezone.now())


# 转化时间戳为datetime，包含Timezone信息

def parse_TimeStamp(data):
    return datetime.datetime.fromtimestamp(data,pytz.timezone(settings.TIME_ZONE))
    